package jrunner;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;


public class ExportPersonObject implements ExportPersonData {
	private FileOutputStream fos;
	private ObjectOutputStream oos;
	
	public void exportPersonData(Person p) {

		Person person = p;
		File directory = new File ("personData");
		File file = new File(directory.getName()+"/"+person.getName()+".person");
		
		if(!directory.exists()){
			directory.mkdir();
		}
		if(!file.exists()){
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		try {
			fos = new FileOutputStream(file);
		} 
		catch (FileNotFoundException e) {	
			e.printStackTrace();}
		
		try {
			oos = new ObjectOutputStream(fos);
			oos.writeObject(person); //hier liegt der Fehler!
			oos.close();

		} 
		catch (IOException e) {
			e.printStackTrace();}
		
	}

}
